package com.yk.faceapplication.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.alibaba.fastjson.JSON;
import com.allinpay.xed.R;
import com.android.volley.VolleyError;
import com.yk.faceapplication.adapter.RequestAccountAdapter;
import com.yk.faceapplication.callback.RequestCallback;
import com.yk.faceapplication.entity.LoanRecord;
import com.yk.faceapplication.entity.RecordRecent;
import com.yk.faceapplication.http.RequestUrl;
import com.yk.faceapplication.util.RequestUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RequestListActivity extends BaseActivity{
    private ListView proLV;
    private RequestAccountAdapter proAdapter;
    private List<LoanRecord> records;
    @Override
    public void onClick(View v) {
        super.onClick(v);
    }

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setTitle("我的申请");
        proLV = (ListView) findViewById(R.id.request_list) ;
        getRequests();
    }

    private void getRequests() {

        Map<String, String> form = new HashMap<String, String>();

        RequestCallback callback = new RequestCallback() {
            @Override
            public void success(JSONObject jsonObject) {
                try {
                records = JSON.parseArray(jsonObject.getJSONObject("data").getString("records"), LoanRecord.class);
                    proLV.setAdapter(new RequestAccountAdapter(mApplication,records));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

            @Override
            public void fail(VolleyError volleyError) {

            }
        };
        RequestUtil.request(this, RequestUrl.GET_REQUESTS +"token="+mToken, callback, form);
    }
}
